library(sf)
library(tidyverse)
library(ggplot2)
library(janitor)
package ‘janitor’ was built under R version 3.6.2
Attaching package: ‘janitor’
The following objects are masked from ‘package:stats’:
chisq.test, fisher.test
loc_authority_with_extra_density_2019 <- read_csv("data/loc_authority_with_extra_density_2019.csv")
── Column specification ─────────────────────────────────────────────────────────────────────────────────
cols(
year = col_double(),
feature_code = col_character(),
local_authority = col_character(),
less_than_11_mins = col_double(),
an_11_minute_walk_or_more = col_double(),
a_5_minute_walk_or_less = col_double(),
within_a_6_10_minute_walk = col_double(),
dont_know = col_double(),
median_age = col_double(),
population_density = col_double(),
population_density_deciles = col_double(),
age_0_15_percent = col_double(),
age_65_percent = col_double(),
old_age_dependency_ratio_oadr = col_double()
)
urban_rural_2019_with_ex_den <- read_csv("data/urban_rural_2019_with_ex_den.csv")
── Column specification ─────────────────────────────────────────────────────────────────────────────────
cols(
year = col_double(),
feature_code = col_character(),
local_authority = col_character(),
type = col_character(),
class = col_character(),
less_than_11_mins = col_double(),
an_11_minute_walk_or_more = col_double(),
a_5_minute_walk_or_less = col_double(),
within_a_6_10_minute_walk = col_double(),
dont_know = col_double(),
median_age = col_double(),
population_density = col_double(),
population_density_deciles = col_double(),
age_0_15_percent = col_double(),
age_65_percent = col_double(),
old_age_dependency_ratio_oadr = col_double()
)
la <- st_read("https://opendata.arcgis.com/datasets/2698b6825e88404ab6272a5ff7f59ee6_0.geojson")
Reading layer `Local_Authority_Districts_(December_2018)_Boundaries_UK_BGC' from data source `https://opendata.arcgis.com/datasets/2698b6825e88404ab6272a5ff7f59ee6_0.geojson' using driver `GeoJSON'
Simple feature collection with 391 features and 10 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -8.649996 ymin: 49.86478 xmax: 1.763571 ymax: 60.86078
CRS: 4326
loc_authority_with_extra_density_2019 #S12000049 #S12000050
loc_authority_with_extra_density_2019 <-
loc_authority_with_extra_density_2019 %>%
mutate(feature_code = recode(feature_code, S12000049 = "S12000046", S12000050 = "S12000044"
)
)
urban_rural_2019_with_ex_den <-
urban_rural_2019_with_ex_den %>%
mutate(feature_code = recode(feature_code, S12000049 = "S12000046", S12000050 = "S12000044"
)
)
la %>%
filter(lad18nm == "North Lanarkshire") #S12000046 S12000044
Simple feature collection with 1 feature and 10 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -4.19449 ymin: 55.73476 xmax: -3.711127 ymax: 56.03136
CRS: 4326
objectid lad18cd lad18nm lad18nmw bng_e bng_n long lat st_areashape
1 365 S12000044 North Lanarkshire 277984 665608 -3.9514 55.8681 472257663
st_lengthshape geometry
1 160705.9 MULTIPOLYGON (((-4.020121 5...
la_loc_authority_ex_den <- inner_join(loc_authority_with_extra_density_2019, la, by = c("feature_code" = "lad18cd"))
la_loc_authority_ex_den
la_urban_rural_2019 <- left_join(urban_rural_2019_with_ex_den, la, by = c("feature_code" = "lad18cd"))
la_urban_rural_2019
la_loc_authority_ex_den_no_shetland <-
la_loc_authority_ex_den %>%
filter(local_authority != "Shetland Islands")
la_loc_authority_ex_den_with_shetland <-
la_loc_authority_ex_den %>%
filter(local_authority == "Shetland Islands")
map_1_5_min_walk <-
ggplot() +
geom_sf(data = la_loc_authority_ex_den_no_shetland, mapping = aes(geometry = geometry, fill = a_5_minute_walk_or_less), colour = "grey", size = 0.005) +
theme_void() +
labs(title = "Percentage of Population Within a 5-minute Walk of Green Space",
subtitle = "Mean figures between 2013 - 2019 - Scotland",
fill = "% within 5 min Green Space") +
theme(legend.key.size = unit(0.3, "cm"),
legend.key.width = unit(0.3, "cm"),
legend.title = element_text(size = 7),
legend.text = element_text(size = 8),
plot.title = element_text(size = 12, hjust = 0.2),
plot.subtitle = element_text(size = 10, hjust = 0.067)
)
extra_5_mins_shetland <-
ggplot() +
geom_sf(data = la_loc_authority_ex_den_with_shetland, mapping = aes(geometry = geometry, fill = a_5_minute_walk_or_less), colour = "grey", size = 0.005) +
theme_void() +
theme(
legend.position = "none"
)
map_2_pop_density <-
ggplot() +
geom_sf(data = la_loc_authority_ex_den_no_shetland, mapping = aes(geometry = geometry, fill = factor(population_density_deciles)), colour = "grey", size = 0.005) +
theme_void() +
labs(title = "Population Density",
fill = "Pop. Density Deciles (ONS)") +
theme(legend.key.size = unit(0.3, "cm"),
legend.key.width = unit(0.3, "cm"),
legend.title = element_text(size = 7),
legend.text = element_text(size = 8),
plot.title = element_text(size = 12, hjust = 0.1),
) +
scale_fill_hue(h = c(180, 390),
l = 50, c = 70)
extra_pop_dens_shetland <-
ggplot() +
geom_sf(data = la_loc_authority_ex_den_with_shetland, mapping = aes(geometry = geometry, fill = factor(population_density_deciles)), colour = "grey", size = 0.005) +
theme_void() +
theme(
legend.position = "none") +
scale_fill_hue(h = c(180, 390),
l = 50, c = 70)
extra_pop_dens_shetland %>%
ggsave(filename="~/presentation_pngs/extra_pop_dens_shetland.png",
device="png",
dpi=500)
Saving 7 x 7 in image
write_csv(la_loc_authority_ex_den, "data/presentation_data/map_2_la_loc_authority_ex_den.csv")
write_csv(la_urban_rural_2019, "data/presentation_data/map_3_la_urban_rural_2019.csv")
la_urban_rural_2019_from_file <- read_csv("data/presentation_data/map_2_la_loc_authority_ex_den.csv") %>% clean_names()
la_urban_rural_2019_from_file